import configparser
import os


class ReadConfig:
    """定义一个读取配置文件的类"""

    def __init__(self, filepath=None):
        if filepath:
            configpath = filepath
        else:
            root_dir = os.path.dirname(os.path.abspath('.')) + '/Teambition'

            configpath = os.path.join(root_dir, "config.ini")
        self.config = configparser.ConfigParser()
        self.config.read(configpath)

    def flask_config(self, param):
        value = self.config.get("Flask", param)
        return value

    def db(self, param):
        value = self.config.get("db", param)
        return value

    def save_xls(self, param):
        value = self.config.get("save_xls", param)
        return value

    def email(self, param):
        value = self.config.get("email", param)
        return value

    def user_pwd(self, param):
        value = self.config.get("Teambition", param)
        return value


if __name__ == '__main__':
    test = ReadConfig()
    t = test.save_xls('save_to_xls')
    print(t)
